#include "CommonDef.h"

void UserInfo::xml2Val()
{
    element2Val("id", id);
    element2Val("name", name);
    element2Val("ico", ico);
    element2ValVec("histroyScore", histroyScore);
}

void UserInfo::val2Xml()
{
    val2Element("id", id);
    val2Element("name", name);
    val2Element("ico", ico);
    valVec2Element("histroyScore", histroyScore);
}

UserInfo::~UserInfo()
{
    histroyScore.clear();
}

void SettingConf::xml2Val()
{
    element2Val("SessionType", SessionType);
    element2Val("CanChi", CanChi);
    element2Val("CanPeng", CanPeng);
    element2Val("CanGang", CanGang);
    element2Val("CanHu", CanHu);
}

void SettingConf::val2Xml()
{
    val2Element("SessionType", SessionType);
    val2Element("CanChi", CanChi);
    val2Element("CanPeng", CanPeng);
    val2Element("CanGang", CanGang);
    val2Element("CanHu", CanHu);
}

Chess::Chess()
{
    id = 0;
    type = ChessType::BING;
    count = 0;
}

Chess::Chess(ChessType tp, short ct)
{
    id = 0;
    type = tp;
    count = ct;
}

Chess::Chess(const Chess& rhs)
{
    id = rhs.id;
    type = rhs.type;
    count = rhs.count;
}

const Chess& Chess::operator=(const Chess& rhs)
{
    if (this == &rhs)
    {
        return rhs;
    }
    id = rhs.id;
    type = rhs.type;
    count = rhs.count;
    return *this;
}

bool Chess::operator==(const Chess& rhs) const
{
    return ((type == rhs.type) &&
        (count == rhs.count));
}

bool Chess::operator!=(const Chess& rhs) const
{
    return ((type != rhs.type) ||
        (count != rhs.count));
}

bool Chess::operator<(const Chess& rhs) const
{
    return (getIdentify() < rhs.getIdentify());
}

short Chess::getIdentify() const
{
    return type * 100 + count * 10 + id;
}

short Chess::getTypeIdentify() const
{
    return type * 100 + count * 10;
}

KindChess::~KindChess()
{
    item.clear();
}

bool KindChess::operator==(const KindChess& rhs) const
{
    if (type != rhs.type)
    {
        return false;
    }

    if (item.size() != rhs.item.size())
    {
        return false;
    }

    for (size_t i = 0; i < item.size(); i++)
    {
        if (item.at(i).getIdentify() != rhs.item.at(i).getIdentify())
        {
            return false;
        }
    }

    return true;
}